package forum_system_test;

import org.junit.jupiter.api.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

/**
 * @author tongchen
 * @create 2023-08-19 15:21
 */
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class EditPageTest {
    private static ChromeDriver chromeDriver=TestUtils.getDriver();
    //首先页面登录，并且进行页面跳转
    @BeforeAll
public static void loginAndClick() throws InterruptedException {
        chromeDriver.get("http://47.93.222.41:58080/sign-in.html");
        WebElement element = chromeDriver.findElement(By.cssSelector("#username"));
        WebElement element1 = chromeDriver.findElement(By.cssSelector("#password"));
        WebElement element2 = chromeDriver.findElement(By.cssSelector("#submit"));
        element.clear();
        element1.clear();
        element.sendKeys("刘健磊");
        element1.sendKeys("123456");
        //强制等待一秒，使新页面能加载出来
        element2.click();
        Thread.sleep(5000);
        //点击页面对应元素
        chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")).click();
        //等待新页面加载完成
        Thread.sleep(3000);
    }
    @Test
    @Order(1)
    public void testEdit() throws InterruptedException {
        //找到下拉框元素并进行点击操作
        Select select = new Select(chromeDriver.findElement(By.cssSelector("#article_post_borad")));
        select.selectByIndex(0);
        //输入文章标题
        chromeDriver.findElement(By.cssSelector("#article_post_title")).sendKeys("Valorant");
        //找到元素并输入内容
        Thread.sleep(10000);//失效进行手动填写
        //先点击其他部分
        chromeDriver.findElement(By.cssSelector("#article_post_content")).click();
        chromeDriver.findElement(By.cssSelector("#article_post_content")).sendKeys("测试测试");
        //测试其他按钮是否有效
        //找到发布按钮并进行文章的发布
        chromeDriver.findElement(By.cssSelector("#article_post_submit")).submit();
    }
}
